﻿using Liang.Device.Model.Camera;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace Liang.Device.Camera.Dll
{
    /// <summary>
    /// 海康威视摄像头DLL
    /// </summary>
    public static class HikVisionDll
    {
        /// <summary>
        /// 初始化海康摄像头SDK
        /// </summary>
        /// <returns></returns>
        [DllImport("KsCamera_HC.dll")]
        public static extern Boolean KsCamera_HC_InitSDK();

        /// <summary>
        /// 注销SDK
        /// </summary>
        [DllImport("KsCamera_HC.dll")]
        public static extern void KsCamera_HC_CleanupSDK();

        // int WINAPI KsCamera_HC_Login(const HWND hPlayWnd, LPCTSTR szIPAddr, const WORD nPort, LPCTSTR szUser, LPCTSTR szPassword)
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="hPlayWnd">播放窗口句柄</param>
        /// <param name="szIPAddr">摄像头IP地址</param>
        /// <param name="nPort">摄像头端口</param>
        /// <param name="szUser">账号</param>
        /// <param name="szPassword">密码</param>
        /// <returns></returns>
        [DllImport("KsCamera_HC.dll")]
        public static extern int KsCamera_HC_Login(IntPtr hPlayWnd, string szIPAddr, short nPort, string szUser, string szPassword);

        // void WINAPI KsCamera_HC_Logout(const int nLoginID)
        /// <summary>
        /// 登出
        /// </summary>
        /// <param name="nLoginID"></param>
        [DllImport("KsCamera_HC.dll")]
        public static extern void KsCamera_HC_Logout(int nLoginID);

        /// <summary>
        /// 实时播放
        /// </summary>
        /// <param name="nLoginID"></param>
        /// <param name="nChannel"></param>
        /// <returns></returns>
        [DllImport("KsCamera_HC.dll")]
        public static extern Boolean KsCamera_HC_RealPlay(int nLoginID, int nChannel);

        // void WINAPI KsCamera_HC_StopPlay(const int nLoginID)
        /// <summary>
        /// 停止播放
        /// </summary>
        /// <param name="nLoginID"></param>
        [DllImport("KsCamera_HC.dll")]
        public static extern void KsCamera_HC_StopPlay(int nLoginID);

        /// <summary>
        /// 抓拍
        /// </summary>
        /// <param name="nLoginID"></param>
        /// <param name="szImagePath"></param>
        /// <returns></returns>
        [DllImport("KsCamera_HC.dll")]
        public static extern bool KsCamera_HC_CaptureImage(int nLoginID, string szImagePath);

        /// <summary>
        /// 注册IO报警抓拍
        /// </summary>
        /// <param name="hAlarmWnd"></param>
        /// <param name="nIOAlarmMsg"></param>
        /// <param name="szImagePath"></param>
        /// <returns></returns>
        [DllImport("KsCamera_HC.dll")]
        public static extern bool KsCamera_HC_SetIOAlarmCapture(IntPtr hAlarmWnd, uint nIOAlarmMsg, string szImagePath);

        /// <summary>
        /// IO 报警使能
        /// </summary>
        /// <param name="nLoginID"></param>
        /// <param name="bNewAlarm">上传报警信息类型: <para>true: 新报警信息</para><para>false: 老报警信息</para></param>
        /// <param name="bEnable">是否启用IO报警</param>
        /// <returns></returns>
        [DllImport("KsCamera_HC.dll")]
        public static extern bool KsCamera_HC_EnableIOCapture(int nLoginID, bool bNewAlarm, bool bEnable);

        /// <summary>
        /// 获取IO报警抓拍数据
        /// </summary>
        /// <param name="nCaptureId"></param>
        /// <param name="pIOAlarmCapture"></param>
        /// <returns></returns>
        [DllImport("KsCamera_HC.dll")]
        public static extern bool KsCamera_HC_GetIOAlarmCaptureImage(int nCaptureId, ref HikIOAlarmCapture pIOAlarmCapture);

        /// <summary>
        /// 手动触发IO报警抓拍
        /// </summary>
        /// <param name="nLoginID"></param>
        /// <param name="nRoadNo"></param>
        /// <param name="nSnapTimes"></param>
        /// <param name="nSnapWaitTime"></param>
        /// <param name="nIntervalTime"></param>
        [DllImport("KsCamera_HC.dll")]
        public static extern bool KsCamera_HC_ManualIOAlarmCapture(int nLoginID, byte nRoadNo, byte nSnapTimes, short nSnapWaitTime, short nIntervalTime);
    }
}
